package com.zzyl.nursing.service.member.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.dto.memberDto.MemberNursingProjectDto;
import com.zzyl.nursing.mapper.member.MemberNursingProjectMapper;
import com.zzyl.nursing.service.member.IMemberNursingProjectService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
public class MemberNursingProjectServiceImpl extends ServiceImpl<MemberNursingProjectMapper, NursingProject> implements IMemberNursingProjectService {

    private final MemberNursingProjectMapper memberNursingProjectMapper;

    @Override
    public IPage<NursingProject> page(MemberNursingProjectDto projectDto) {
        // 创建分页对象，传入当前页和每页大小
        Page<NursingProject> page = new Page<>(projectDto.getPageNum(), projectDto.getPageSize());

        // 执行分页查询，返回分页结果
        IPage<NursingProject> nursingProjectPage = memberNursingProjectMapper.selectPage(page,
                new QueryWrapper<NursingProject>()
                        .like(StringUtils.isNotBlank(projectDto.getName()), "name", projectDto.getName())  // 根据name进行模糊查询
                        .eq(projectDto.getStatus() != null, "status", projectDto.getStatus())  // 根据status进行查询
        );

        // 返回分页后的列表
        return nursingProjectPage;
    }
}
